package android.mobilin;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class ViewActivity extends Activity implements OnClickListener {
	Button reply;
	Button back;
	Intent action;
	TextView r_name;
	TextView r_add;
	TextView r_telfax;
	TextView p_name;
	TextView p_age;
	TextView p_sex;
	TextView p_add;
	TextView p_newadd;
	TextView p_caseno;
	TextView p_datetreat;
	TextView p_category;
	TextView p_classification;
	TextView p_type;
	TextView p_smearondiag;
	TextView h_b4tx;
	TextView h_1;
	TextView h_2;
	TextView h_3;
	TextView h_4;
	TextView h_5;
	TextView h_6;
	TextView h_7;
	TextView h_8;
	TextView h_9;
	TextView h_10;
	TextView r_b4tx;
	TextView r_1;
	TextView r_2;
	TextView r_3;
	TextView r_4;
	TextView r_5;
	TextView r_6;
	TextView r_7;
	TextView r_8;
	TextView r_9;
	TextView r_10;
	TextView z_b4tx;
	TextView z_1;
	TextView z_2;
	TextView z_3;
	TextView z_4;
	TextView z_5;
	TextView z_6;
	TextView z_7;
	TextView z_8;
	TextView z_9;
	TextView z_10;
	TextView e_b4tx;
	TextView e_1;
	TextView e_2;
	TextView e_3;
	TextView e_4;
	TextView e_5;
	TextView e_6;
	TextView e_7;
	TextView e_8;
	TextView e_9;
	TextView e_10;
	TextView s_b4tx;
	TextView s_1;
	TextView s_2;
	TextView s_3;
	TextView s_4;
	TextView s_5;
	TextView s_6;
	TextView s_7;
	TextView s_8;
	TextView s_9;
	TextView s_10;
	TextView smear_b4tx;
	TextView smear_1;
	TextView smear_2;
	TextView smear_3;
	TextView smear_4;
	TextView smear_5;
	TextView smear_6;
	TextView smear_7;
	TextView smear_8;
	TextView smear_9;
	TextView smear_10;
	TextView remarks;
	TextView h_namedesig;
	TextView p_datereferred;
	DBAdapter db;
	String refer_number;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.view);
		db=new DBAdapter(this);
		
		reply=(Button)findViewById(R.id.createReply);
		reply.setOnClickListener(this);
		back=(Button)findViewById(R.id.backReply);
		back.setOnClickListener(this);
		r_name=(TextView)findViewById(R.id.r_name);
		r_add=(TextView)findViewById(R.id.r_add);
		r_telfax=(TextView)findViewById(R.id.r_telfax);
		p_name=(TextView)findViewById(R.id.p_name);
		p_age=(TextView)findViewById(R.id.p_age);
		p_sex=(TextView)findViewById(R.id.p_sex);
		p_add=(TextView)findViewById(R.id.p_add);
		p_newadd=(TextView)findViewById(R.id.p_newadd);
		p_caseno=(TextView)findViewById(R.id.p_caseno);
		p_datetreat=(TextView)findViewById(R.id.p_datetreat);
		p_category=(TextView)findViewById(R.id.p_category);
		p_classification=(TextView)findViewById(R.id.p_classification);
		p_type=(TextView)findViewById(R.id.p_type);
		p_smearondiag=(TextView)findViewById(R.id.p_smearondiag);
		h_b4tx=(TextView)findViewById(R.id.h_b4tx);
		h_1=(TextView)findViewById(R.id.h_1);
		h_2=(TextView)findViewById(R.id.h_2);
		h_3=(TextView)findViewById(R.id.h_3);
		h_4=(TextView)findViewById(R.id.h_4);
		h_5=(TextView)findViewById(R.id.h_5);
		h_6=(TextView)findViewById(R.id.h_6);
		h_7=(TextView)findViewById(R.id.h_7);
		h_8=(TextView)findViewById(R.id.h_8);
		h_9=(TextView)findViewById(R.id.h_9);
		h_10=(TextView)findViewById(R.id.h_10);
		r_b4tx=(TextView)findViewById(R.id.r_b4tx);
		r_1=(TextView)findViewById(R.id.r_1);
		r_2=(TextView)findViewById(R.id.r_2);
		r_3=(TextView)findViewById(R.id.r_3);
		r_4=(TextView)findViewById(R.id.r_4);
		r_5=(TextView)findViewById(R.id.r_5);
		r_6=(TextView)findViewById(R.id.r_6);
		r_7=(TextView)findViewById(R.id.r_7);
		r_8=(TextView)findViewById(R.id.r_8);
		r_9=(TextView)findViewById(R.id.r_9);
		r_10=(TextView)findViewById(R.id.r_10);
		z_b4tx=(TextView)findViewById(R.id.z_b4tx);
		z_1=(TextView)findViewById(R.id.z_1);
		z_2=(TextView)findViewById(R.id.z_2);
		z_3=(TextView)findViewById(R.id.z_3);
		z_4=(TextView)findViewById(R.id.z_4);
		z_5=(TextView)findViewById(R.id.z_5);
		z_6=(TextView)findViewById(R.id.z_6);
		z_7=(TextView)findViewById(R.id.z_7);
		z_8=(TextView)findViewById(R.id.z_8);
		z_9=(TextView)findViewById(R.id.z_9);
		z_10=(TextView)findViewById(R.id.z_10);
		e_b4tx=(TextView)findViewById(R.id.e_b4tx);
		e_1=(TextView)findViewById(R.id.e_1);
		e_2=(TextView)findViewById(R.id.e_2);
		e_3=(TextView)findViewById(R.id.e_3);
		e_4=(TextView)findViewById(R.id.e_4);
		e_5=(TextView)findViewById(R.id.e_5);
		e_6=(TextView)findViewById(R.id.e_6);
		e_7=(TextView)findViewById(R.id.e_7);
		e_8=(TextView)findViewById(R.id.e_8);
		e_9=(TextView)findViewById(R.id.e_9);
		e_10=(TextView)findViewById(R.id.e_10);
		s_b4tx=(TextView)findViewById(R.id.s_b4tx);
		s_1=(TextView)findViewById(R.id.s_1);
		s_2=(TextView)findViewById(R.id.s_2);
		s_3=(TextView)findViewById(R.id.s_3);
		s_4=(TextView)findViewById(R.id.s_4);
		s_5=(TextView)findViewById(R.id.s_5);
		s_6=(TextView)findViewById(R.id.s_6);
		s_7=(TextView)findViewById(R.id.s_7);
		s_8=(TextView)findViewById(R.id.s_8);
		s_9=(TextView)findViewById(R.id.s_9);
		s_10=(TextView)findViewById(R.id.s_10);
		smear_b4tx=(TextView)findViewById(R.id.smear_b4tx);
		smear_1=(TextView)findViewById(R.id.smear_1);
		smear_2=(TextView)findViewById(R.id.smear_2);
		smear_3=(TextView)findViewById(R.id.smear_3);
		smear_4=(TextView)findViewById(R.id.smear_4);
		smear_5=(TextView)findViewById(R.id.smear_5);
		smear_6=(TextView)findViewById(R.id.smear_6);
		smear_7=(TextView)findViewById(R.id.smear_7);
		smear_8=(TextView)findViewById(R.id.smear_8);
		smear_9=(TextView)findViewById(R.id.smear_9);
		smear_10=(TextView)findViewById(R.id.smear_10);
		remarks=(TextView)findViewById(R.id.p_remarks);
		h_namedesig=(TextView)findViewById(R.id.h_namedesig);
		p_datereferred=(TextView)findViewById(R.id.p_datereferred);
		Cursor c=db.query("form");
		if(c!=null) {
			int col_refer_number=c.getColumnIndex("refer_no");
			int col_r_name=c.getColumnIndex("r_name");
			int col_r_add=c.getColumnIndex("r_add");
			int col_r_telfax=c.getColumnIndex("r_telfax");
			int col_p_name=c.getColumnIndex("p_name");
			int col_p_age=c.getColumnIndex("p_age");
			int col_p_sex=c.getColumnIndex("p_sex");
			int col_p_add=c.getColumnIndex("p_add");
			int col_p_newadd=c.getColumnIndex("p_newadd");
			int col_p_caseno=c.getColumnIndex("p_caseno");
			int col_p_datetreat=c.getColumnIndex("p_datetreat");
			int col_p_category=c.getColumnIndex("p_category");
			int col_p_classification=c.getColumnIndex("p_classification");
			int col_p_type=c.getColumnIndex("p_type");
			int col_p_smearondiag=c.getColumnIndex("p_smearondiag");
			int col_h_b4tx=c.getColumnIndex("h_b4tx");
			int col_h_treat=c.getColumnIndex("h_treat");
			int col_r_b4tx=c.getColumnIndex("r_b4tx");
			int col_r_treat=c.getColumnIndex("r_treat");
			int col_z_b4tx=c.getColumnIndex("z_b4tx");
			int col_z_treat=c.getColumnIndex("z_treat");
			int col_e_b4tx=c.getColumnIndex("e_b4tx");
			int col_e_treat=c.getColumnIndex("e_treat");
			int col_s_b4tx=c.getColumnIndex("s_b4tx");
			int col_s_treat=c.getColumnIndex("s_treat");
			int col_smear_b4tx=c.getColumnIndex("smear_b4tx");
			int col_smear_treat=c.getColumnIndex("smear_treat");
			int col_remarks=c.getColumnIndex("remarks");
			int col_h_name=c.getColumnIndex("h_name");
			int col_h_designation=c.getColumnIndex("h_name");
			int col_p_datereferred=c.getColumnIndex("referdate");
    		if(c.moveToNext()) {
    			refer_number=c.getString(col_refer_number);
    			r_name.setText(c.getString(col_r_name));
    			r_add.setText(c.getString(col_r_add));
    			r_telfax.setText(c.getString(col_r_telfax));
    			p_name.setText(c.getString(col_p_name));
    			p_age.setText(c.getString(col_p_age));
    			p_sex.setText(c.getString(col_p_sex));
    			p_add.setText(c.getString(col_p_add));
    			p_newadd.setText(c.getString(col_p_newadd));
    			p_caseno.setText(c.getString(col_p_caseno));
    			p_datetreat.setText(c.getString(col_p_datetreat));
    			p_category.setText(c.getString(col_p_category));
    			p_classification.setText(c.getString(col_p_classification));
    			p_type.setText(c.getString(col_p_type));
    			p_smearondiag.setText(c.getString(col_p_smearondiag));
    			h_b4tx.setText(c.getString(col_h_b4tx));
    			String hdrug=c.getString(col_h_treat);
    			h_1.setText(hdrug.charAt(0));
    			h_2.setText(hdrug.charAt(1));
    			h_3.setText(hdrug.charAt(2));
    			h_4.setText(hdrug.charAt(3));
    			h_5.setText(hdrug.charAt(4));
    			h_6.setText(hdrug.charAt(5));
    			h_7.setText(hdrug.charAt(6));
    			h_8.setText(hdrug.charAt(7));
    			h_9.setText(hdrug.charAt(8));
    			h_10.setText(hdrug.charAt(9));
    			r_b4tx.setText(c.getString(col_r_b4tx));
    			String rdrug=c.getString(col_r_treat);
    			r_1.setText(rdrug.charAt(0));
    			r_2.setText(rdrug.charAt(1));
    			r_3.setText(rdrug.charAt(2));
    			r_4.setText(rdrug.charAt(3));
    			r_5.setText(rdrug.charAt(4));
    			r_6.setText(rdrug.charAt(5));
    			r_7.setText(rdrug.charAt(6));
    			r_8.setText(rdrug.charAt(7));
    			r_9.setText(rdrug.charAt(8));
    			r_10.setText(rdrug.charAt(9));
    			z_b4tx.setText(c.getString(col_z_b4tx));
    			String zdrug=c.getString(col_z_treat);
    			z_1.setText(zdrug.charAt(0));
    			z_2.setText(zdrug.charAt(1));
    			z_3.setText(zdrug.charAt(2));
    			z_4.setText(zdrug.charAt(3));
    			z_5.setText(zdrug.charAt(4));
    			z_6.setText(zdrug.charAt(5));
    			z_7.setText(zdrug.charAt(6));
    			z_8.setText(zdrug.charAt(7));
    			z_9.setText(zdrug.charAt(8));
    			z_10.setText(zdrug.charAt(9));
    			e_b4tx.setText(c.getString(col_e_b4tx));
    			String edrug=c.getString(col_e_treat);
    			e_1.setText(edrug.charAt(0));
    			e_2.setText(edrug.charAt(1));
    			e_3.setText(edrug.charAt(2));
    			e_4.setText(edrug.charAt(3));
    			e_5.setText(edrug.charAt(4));
    			e_6.setText(edrug.charAt(5));
    			e_7.setText(edrug.charAt(6));
    			e_8.setText(edrug.charAt(7));
    			e_9.setText(edrug.charAt(8));
    			e_10.setText(edrug.charAt(9));
    			s_b4tx.setText(c.getString(col_s_b4tx));
    			String sdrug=c.getString(col_s_treat);
    			s_1.setText(sdrug.charAt(0));
    			s_2.setText(sdrug.charAt(1));
    			s_3.setText(sdrug.charAt(2));
    			s_4.setText(sdrug.charAt(3));
    			s_5.setText(sdrug.charAt(4));
    			s_6.setText(sdrug.charAt(5));
    			s_7.setText(sdrug.charAt(6));
    			s_8.setText(sdrug.charAt(7));
    			s_9.setText(sdrug.charAt(8));
    			s_10.setText(sdrug.charAt(9));
    			smear_b4tx.setText(c.getString(col_smear_b4tx));
    			String smeardrug=c.getString(col_smear_treat);
    			smear_1.setText(smeardrug.charAt(0));
    			smear_2.setText(smeardrug.charAt(1));
    			smear_3.setText(smeardrug.charAt(2));
    			smear_4.setText(smeardrug.charAt(3));
    			smear_5.setText(smeardrug.charAt(4));
    			smear_6.setText(smeardrug.charAt(5));
    			smear_7.setText(smeardrug.charAt(6));
    			smear_8.setText(smeardrug.charAt(7));
    			smear_9.setText(smeardrug.charAt(8));
    			smear_10.setText(smeardrug.charAt(9));
    			
    			changeColor(h_b4tx);
    			changeColor(h_1);
    			changeColor(h_2);
    			changeColor(h_3);
    			changeColor(h_4);
    			changeColor(h_5);
    			changeColor(h_6);
    			changeColor(h_7);
    			changeColor(h_8);
    			changeColor(h_9);
    			changeColor(h_10);
    			changeColor(r_b4tx);
    			changeColor(r_1);
    			changeColor(r_2);
    			changeColor(r_3);
    			changeColor(r_4);
    			changeColor(r_5);
    			changeColor(r_6);
    			changeColor(r_7);
    			changeColor(r_8);
    			changeColor(r_9);
    			changeColor(r_10);
    			changeColor(z_b4tx);
    			changeColor(z_1);
    			changeColor(z_2);
    			changeColor(z_3);
    			changeColor(z_4);
    			changeColor(z_5);
    			changeColor(z_6);
    			changeColor(z_7);
    			changeColor(z_8);
    			changeColor(z_9);
    			changeColor(z_10);
    			changeColor(e_b4tx);
    			changeColor(e_1);
    			changeColor(e_2);
    			changeColor(e_3);
    			changeColor(e_4);
    			changeColor(e_5);
    			changeColor(e_6);
    			changeColor(e_7);
    			changeColor(e_8);
    			changeColor(e_9);
    			changeColor(e_10);
    			changeColor(s_b4tx);
    			changeColor(s_1);
    			changeColor(s_2);
    			changeColor(s_3);
    			changeColor(s_4);
    			changeColor(s_5);
    			changeColor(s_6);
    			changeColor(s_7);
    			changeColor(s_8);
    			changeColor(s_9);
    			changeColor(s_10);
    			changeColor(smear_b4tx);
    			changeColor(smear_1);
    			changeColor(smear_2);
    			changeColor(smear_3);
    			changeColor(smear_4);
    			changeColor(smear_5);
    			changeColor(smear_6);
    			changeColor(smear_7);
    			changeColor(smear_8);
    			changeColor(smear_9);
    			changeColor(smear_10);
    			
    			remarks.setText(c.getString(col_remarks));
    			h_namedesig.setText(c.getString(col_h_name)+" - "+c.getString(col_h_designation));
    			p_datereferred.setText(c.getString(col_p_datereferred));
    		}
    		else {
    			action.setClass(this, ViewActivity.class);
    			startActivity(action);
    		}
    	}
		action=new Intent(this, ReplyActivity.class);
		Bundle bundle = new Bundle();
		bundle.putString("refer_number", refer_number);
		bundle.putString("p_name", p_name.getText().toString());
		bundle.putString("p_age", p_age.getText().toString());
		bundle.putString("p_sex", p_sex.getText().toString());
		action.putExtras(bundle);
	}

	public void onClick(View v) {
		if(v==reply) {
			startActivity(action);
		}
		else if(v==back) {
			finish();
		}
	}
	
	private void changeColor(TextView tv) {
		if(tv.getText().equals("1")) {
			tv.setBackgroundColor(Color.BLUE);
		}
		tv.setText("");
	}
	
}
